package pixelwaks.gui.impl;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.io.IOException;
import java.util.ResourceBundle;

import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.Border;

import common.i18n.ChangeLanguage;
import common.i18n.IChangeLanguage;
import common.util.FileHandler;

import pixelwaks.ctrl.ControlFactory;

public class SplashScreenPanel extends JPanel implements IChangeLanguage{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JButton ssStart = new JButton();
	
	public SplashScreenPanel() {
		setLayout(new FlowLayout());
		ChangeLanguage.addObserver(this);
		initComponents();
		initControls();
		setLanguage(ChangeLanguage.currentLanguage);
	}
	
	public void initComponents() {
		// how to use BackgroundBorder to set a background image
		try {
			Border border = new BackgroundBorder(FileHandler.getImage("", "splash.png"));
			setBorder(border);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
		ssStart.setFont(new Font("Verdana", Font.PLAIN, 30));
		GridBagLayout layout = new GridBagLayout();
		GridBagConstraints c = new GridBagConstraints();
				
		setLayout(layout);
		
		c.anchor = GridBagConstraints.CENTER;
		c.weightx = 1;
		c.weighty = 1;
		
		add(ssStart, c);
		setPreferredSize(new Dimension(MainFrame.WIDTH_ON_WINDOW,MainFrame.HEIGHT_ON_WINDOW));
		setVisible(true);
	}
	
	public void initControls() {
		Action a = (Action) ControlFactory.getObserver(ControlFactory.SPLASH_CTRL);
		ssStart.setAction(a);
		a.putValue("Splash.ssStart", ssStart);
	}
	

	@Override
	public void setLanguage(ResourceBundle rb) {
		ssStart.setText(rb.getString("ssStart"));
		
	}
}
